```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java List排序方法全解析</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            overflow-x: auto;
        }
        .method-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: 2px;
            width: 100%;
            height: 10px;
            background-color: rgba(118, 75, 162, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 15px;
            background-color: rgba(118, 75, 162, 0.3);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-6xl font-bold mb-6 font-serif">Java List<span class="highlight">排序方法</span>全解析</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 max-w-3xl mx-auto">探索Java中高效、优雅的数据排序技术</p>
            <div class="flex justify-center space-x-4">
                <a href="#methods" class="bg-white text-indigo-700 hover:bg-gray-100 px-6 py-3 rounded-full font-medium transition duration-300 shadow-md">查看方法</a>
                <a href="#comparison" class="border-2 border-white text-white hover:bg-white hover:text-indigo-700 px-6 py-3 rounded-full font-medium transition duration-300">对比分析</a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12 md:py-20">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="bg-white rounded-xl shadow-lg p-8 md:p-10">
                <h2 class="text-3xl font-bold mb-6 text-gray-800 font-serif">Java List排序概述</h2>
                <p class="text-lg text-gray-700 mb-6">在Java开发中，<span class="font-semibold text-indigo-600">List排序</span>是最常见的操作之一。无论是处理用户数据、分析结果还是优化性能，掌握各种排序方法都能让您的代码更高效、更优雅。</p>
                <div class="flex items-center text-indigo-600">
                    <i class="fas fa-lightbulb text-2xl mr-3"></i>
                    <p class="font-medium">本文将带您全面了解Java中List的7种排序方法，从传统方式到现代函数式编程，助您成为排序大师！</p>
                </div>
            </div>
        </section>

        <!-- Methods Section -->
        <section id="methods" class="mb-20">
            <h2 class="text-3xl font-bold mb-10 text-center text-gray-800 font-serif">七大排序方法详解</h2>
            
            <!-- Method 1 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-indigo-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">1</div>
                                <h3 class="text-xl font-bold text-gray-800">Collections.sort()</h3>
                            </div>
                            <p class="text-gray-700">最经典的排序方法，使用归并排序算法，具有稳定性（相等元素保持原有顺序）。</p>
                            <div class="mt-4 flex items-center text-sm text-indigo-600">
                                <i class="fas fa-check-circle mr-2"></i>
                                <span>适合传统排序需求</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="code-block p-4 mb-4">
                            <pre><code class="language-java">import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CollectionsSortDemo {
    public static void main(String[] args) {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();
        list.add("Banana");
        list.add("Apple");
        list.add("Orange");

        // 默认排序（按自然顺序排序）
        Collections.sort(list);

        System.out.println("排序后的 List：");
        for (String item : list) {
            System.out.println(item);
        }
    }
}</code></pre>
                        </div>
                        <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                            <p class="text-blue-800"><span class="font-semibold">专业提示：</span> Collections.sort() 在Java 7之前使用归并排序，之后改进为TimSort算法，结合了归并和插入排序的优点。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 2 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-purple-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-purple-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">2</div>
                                <h3 class="text-xl font-bold text-gray-800">List.sort()</h3>
                            </div>
                            <p class="text-gray-700">Java 8引入的现代方法，直接在List接口中提供，更符合面向对象设计原则。</p>
                            <div class="mt-4 flex items-center text-sm text-purple-600">
                                <i class="fas fa-bolt mr-2"></i>
                                <span>更现代的API设计</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="code-block p-4 mb-4">
                            <pre><code class="language-java">import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class ListSortDemo {
    public static void main(String[] args) {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();
        list.add("Banana");
        list.add("Apple");
        list.add("Orange");

        // 使用 List.sort() 和自定义比较器排序
        list.sort(Comparator.naturalOrder()); // 按自然顺序排序

        System.out.println("排序后的 List：");
        for (String item : list) {
            System.out.println(item);
        }
    }
}</code></pre>
                        </div>
                        <div class="bg-purple-50 border-l-4 border-purple-500 p-4">
                            <p class="text-purple-800"><span class="font-semibold">最佳实践：</span> 在Java 8及以上版本中，优先使用List.sort()方法，代码更简洁且直接表明操作对象。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 3 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-pink-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-pink-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">3</div>
                                <h3 class="text-xl font-bold text-gray-800">Comparator</h3>
                            </div>
                            <p class="text-gray-700">自定义比较器实现复杂排序逻辑，为排序提供无限可能性。</p>
                            <div class="mt-4 flex items-center text-sm text-pink-600">
                                <i class="fas fa-cog mr-2"></i>
                                <span>灵活定制排序规则</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="code-block p-4 mb-4">
                            <pre><code class="language-java">import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CustomComparatorDemo {
    public static void main(String[] args) {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();
        list.add("Banana");
        list.add("Apple");
        list.add("Orange");

        // 自定义比较器（按字符串长度排序）
        Comparator&lt;String&gt; lengthComparator = (s1, s2) -&gt; 
            Integer.compare(s1.length(), s2.length());

        // 使用自定义比较器排序
        Collections.sort(list, lengthComparator);

        System.out.println("排序后的 List：");
        for (String item : list) {
            System.out.println(item);
        }
    }
}</code></pre>
                        </div>
                        <div class="bg-pink-50 border-l-4 border-pink-500 p-4">
                            <p class="text-pink-800"><span class="font-semibold">高级技巧：</span> Java 8的Lambda表达式让Comparator的创建更加简洁，可以轻松实现多字段排序。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 4 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-teal-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-teal-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">4</div>
                                <h3 class="text-xl font-bold text-gray-800">Streams API</h3>
                            </div>
                            <p class="text-gray-700">Java 8的函数式编程方式，配合流处理实现声明式排序。</p>
                            <div class="mt-4 flex items-center text-sm text-teal-600">
                                <i class="fas fa-project-diagram mr-2"></i>
                                <span>函数式编程风格</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="code-block p-4 mb-4">
                            <pre><code class="language-java">import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamSortDemo {
    public static void main(String[] args) {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();
        list.add("Banana");
        list.add("Apple");
        list.add("Orange");

        // 使用流进行排序
        List&lt;String&gt; sortedList = list.stream()
            .sorted() // 默认按自然顺序排序
            .collect(Collectors.toList());

        System.out.println("排序后的 List：");
        for (String item : sortedList) {
            System.out.println(item);
        }
    }
}</code></pre>
                        </div>
                        <div class="bg-teal-50 border-l-4 border-teal-500 p-4">
                            <p class="text-teal-800"><span class="font-semibold">性能考量：</span> Stream API排序会创建新的List，适用于需要保持原列表不变的情况，但会带来轻微性能开销。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 5 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-orange-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-orange-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">5</div>
                                <h3 class="text-xl font-bold text-gray-800">排序稳定性</h3>
                            </div>
                            <p class="text-gray-700">理解排序算法的稳定性对于需要保留相等元素原始顺序的场景至关重要。</p>
                            <div class="mt-4 flex items-center text-sm text-orange-600">
                                <i class="fas fa-balance-scale mr-2"></i>
                                <span>保持相等元素顺序</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="bg-white p-6 rounded-lg mb-4">
                            <h4 class="font-bold text-lg mb-3 text-gray-800">稳定性关键点</h4>
                            <ul class="space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                    <span><span class="font-semibold">稳定排序：</span> Collections.sort() 和 List.sort() 使用的TimSort算法是稳定的</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                    <span><span class="font-semibold">应用场景：</span> 当排序条件相同时，保持元素原有顺序对于多条件排序很重要</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                                    <span><span class="font-semibold">Java实现：</span> Java中不存在不稳定的List排序方法，Array.sort()对基本类型使用快排（不稳定），对象类型使用TimSort（稳定）</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 6 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-blue-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-blue-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">6</div>
                                <h3 class="text-xl font-bold text-gray-800">Comparable接口</h3>
                            </div>
                            <p class="text-gray-700">定义对象的自然排序顺序，使类自身具备可比较性。</p>
                            <div class="mt-4 flex items-center text-sm text-blue-600">
                                <i class="fas fa-object-group mr-2"></i>
                                <span>对象自然顺序</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="code-block p-4 mb-4">
                            <pre><code class="language-java">import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Person implements Comparable&lt;Person&gt; {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() { return name; }
    public int getAge() { return age; }

    @Override
    public int compareTo(Person other) {
        // 自然排序：根据年龄排序
        return Integer.compare(this.age, other.age);
    }

    @Override
    public String toString() {
        return "Person{name='" + name + "', age=" + age + "}";
    }

    public static void main(String[] args) {
        List&lt;Person&gt; people = new ArrayList&lt;&gt;();
        people.add(new Person("Alice", 30));
        people.add(new Person("Bob", 25));
        people.add(new Person("Charlie", 35));

        // 使用 Collections.sort() 对实现了 Comparable 的对象进行排序
        Collections.sort(people);

        System.out.println("按年龄排序后的 List：");
        for (Person person : people) {
            System.out.println(person);
        }
    }
}</code></pre>
                        </div>
                        <div class="bg-blue-50 border-l-4 border-blue-500 p-4">
                            <p class="text-blue-800"><span class="font-semibold">设计原则：</span> 当对象有明确的自然顺序时（如年龄、姓名、日期），实现Comparable接口是面向对象设计的良好实践。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Method 7 -->
            <div class="method-card bg-white rounded-xl shadow-md overflow-hidden mb-8 transition duration-300">
                <div class="md:flex">
                    <div class="md:w-1/3 bg-indigo-50 p-6 md:p-8 flex items-center">
                        <div>
                            <div class="flex items-center mb-4">
                                <div class="bg-indigo-600 text-white rounded-full w-8 h-8 flex items-center justify-center mr-3">7</div>
                                <h3 class="text-xl font-bold text-gray-800">Comparable vs Comparator</h3>
                            </div>
                            <p class="text-gray-700">理解两种比较方式的区别，选择最适合场景的方案。</p>
                            <div class="mt-4 flex items-center text-sm text-indigo-600">
                                <i class="fas fa-random mr-2"></i>
                                <span>策略选择</span>
                            </div>
                        </div>
                    </div>
                    <div class="md:w-2/3 p-6 md:p-8">
                        <div class="bg-white p-6 rounded-lg mb-4">
                            <h4 class="font-bold text-lg mb-4 text-gray-800">比较分析</h4>
                            <div class="overflow-x-auto">
                                <table class="min-w-full divide-y divide-gray-200">
                                    <thead class="bg-gray-50">
                                        <tr>
                                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">特性</th>
                                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Comparable</th>
                                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Comparator</th>
                                        </tr>
                                    </thead>
                                    <tbody class="bg-white divide-y divide-gray-200">
                                        <tr>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">定义位置</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">类内部</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">类外部</td>
                                        </tr>
                                        <tr>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">排序逻辑</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">自然顺序（默认）</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">自定义顺序</td>
                                        </tr>
                                        <tr>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">修改需求</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">需要修改类代码</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">无需修改类代码</td>
                                        </tr>
                                        <tr>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">多排序方式</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">单一</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多个</td>
                                        </tr>
                                        <tr>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">使用场景</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">有明确自然顺序</td>
                                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">需要多种排序方式</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="bg-indigo-50 border-l-4 border-indigo-500 p-4">
                            <p class="text-indigo-800"><span class="font-semibold">决策指南：</span> 通常两种方式可以结合使用 - 使用Comparable定义自然顺序，使用Comparator提供特殊排序需求。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section id="comparison" class="mb-20 bg-white rounded-xl shadow-lg p-8 md:p-10">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 font-serif">排序方法关系图</h2>
            <div class="mermaid">
                graph TD
                    A[Java List排序] --> B[Collections.sort]
                    A --> C[List.sort]
                    A --> D[Stream.sorted]
                    B --> E[使用Comparable]
                    B --> F[使用Comparator]
                    C --> F
                    D --> F
                    E --> G[类实现compareTo]
                    F --> H[lambda表达式]
                    F --> I[方法引用]
                    F --> J[Comparator.comparing]
                    style A fill:#4f46e5,color:white,stroke:#4f46e5
                    style B fill:#7c3aed,color:white
                    style C fill:#7c3aed,color:white
                    style D fill:#7c3aed,color:white
                    style E fill:#10b981,color:white
                    style F fill:#10b981,color:white
                    style G fill:#06b6d4,color:white
                    style H fill:#06b6d4,color:white
                    style I fill:#06b6d4,color:white
                    style J fill:#06b6d4,color:white
            </div>
            <div class="mt-8">
                <h3 class="text-xl font-bold mb-4 text-gray-800">核心概念解读</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <div class="flex items-center mb-3">
                            <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <h4 class="font-bold text-lg">方法分类</h4>
                        </div>
                        <p class="text-gray-700">Java中的List排序方法可以分为三类：传统方法(Collections.sort)、现代API(List.sort)和流式处理(Stream.sorted)。它们底层都依赖于比较逻辑的实现。</p>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <div class="flex items-center mb-3">
                            <div class="bg-purple-100 text-purple-800 rounded-full w-10 h-10 flex items-center justify-center mr-3">
                                <i class="fas fa-code-branch"></i>
                            </div>
                            <h4 class="font-bold text-lg">比较策略</h4>
                        </div>
                        <p class="text-gray-700">比较逻辑可以通过两种方式实现：让类实现Comparable接口定义自然顺序，或使用Comparator提供灵活的外部比较规则。Java 8的Lambda使Comparator更简洁。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-indigo-500 to-purple-600 rounded-xl shadow-lg p-8 md:p-10 text-white">
                <h2 class="text-2xl md:text-3xl font-bold mb-6 font-serif">排序方法选择指南</h2>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h3 class="text-xl font-bold mb-3 flex items-center">
                            <i class="fas fa-check-circle mr-2"></i>
                            <span>推荐场景</span>
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right mt-1 mr-2 text-white opacity-80"></i>
                                <span>简单排序：<span class="font-semibold">List.sort(Comparator.naturalOrder())</span></span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right mt-1 mr-2 text-white opacity-80"></i>
                                <span>对象自然排序：<span class="font-semibold">实现Comparable接口</span></span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right mt-1 mr-2 text-white opacity-80"></i>
                                <span>复杂排序逻辑：<span class="font-semibold">自定义Comparator</span></span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-arrow-right mt-1 mr-2 text-white opacity-80"></i>
                                <span>函数式编程：<span class="font-semibold">Stream.sorted()</span></span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-xl font-bold mb-3 flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2"></i>
                            <span>注意事项</span>
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-times mt-1 mr-2 text-white opacity-80"></i>
                                <span>避免在循环中重复创建Comparator</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times mt-1 mr-2 text-white opacity-80"></i>
                                <span>注意null值的处理(Comparator.nullsFirst/nullsLast)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times mt-1 mr-2 text-white opacity-80"></i>
                                <span>大列表考虑性能(默认TimSort效率已很高)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times mt-1 mr-2 text-white opacity-80"></i>
                                <span>多字段排序注意顺序和反转</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Final Tips -->
        <section class="bg-white rounded-xl shadow-lg p-8 md:p-10 mb-16">
            <h2 class="text-3xl font-bold mb-8 text-gray-800 font-serif">高级技巧与最佳实践</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="flex items-start mb-6">
                        <div class="bg-indigo-100 text-indigo-800 rounded-full w-12 h-12 flex-shrink-0 flex items-center justify-center mr-4">
                            <i class="fas fa-magic text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold mb-2 text-gray-800">多条件排序</h3>
                            <p class="text-gray-700">使用Comparator.thenComparing()实现多字段排序：</p>
                            <div class="code-block p-4 mt-2 text-sm">
                                <pre><code class="language-java">list.sort(Comparator.comparing(Person::getAge)
    .thenComparing(Person::getName));</code></pre>
                            </div>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="bg-purple-100 text-purple-800 rounded-full w-12 h-12 flex-shrink-0 flex items-center justify-center mr-4">
                            <i class="fas fa-sort-amount-down-alt text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold mb-2 text-gray-800">逆序排序</h3>
                            <p class="text-gray-700">使用Comparator.reversed()轻松实现逆序：</p>
                            <div class="code-block p-4 mt-2 text-sm">
                                <pre><code class="language-java">// 自然顺序逆序
list.sort(Comparator.naturalOrder().reversed());

// 自定义比较器逆序
list.sort(Comparator.comparing(String::length).reversed());</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <div class="flex items-start mb-6">
                        <div class="bg-teal-100 text-teal-800 rounded-full w-12 h-12 flex-shrink-0 flex items-center justify-center mr-4">
                            <i class="fas fa-question-circle text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold mb-2 text-gray-800">Null值处理</h3>
                            <p class="text-gray-700">使用Comparator.nullsFirst/nullsLast处理可能为null的值：</p>
                            <div class="code-block p-4 mt-2 text-sm">
                                <pre><code class="language-java">// null值排在最前
Comparator&lt;String&gt; nullsFirst = Comparator.nullsFirst(Comparator.naturalOrder());
list.sort(nullsFirst);

// null值排在最后
Comparator&lt;String&gt; nullsLast = Comparator.nullsLast(Comparator.naturalOrder());
list.sort(nullsLast);</code></pre>
                            </div>
                        </div>
                    </div>
                    <div class="flex items-start">
                        <div class="bg-pink-100 text-pink-800 rounded-full w-12 h-12 flex-shrink-0 flex items-center justify-center mr-4">
                            <i class="fas fa-tachometer-alt text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-xl font-bold mb-2 text-gray-800">性能优化</h3>
                            <p class="text-gray-700">对于频繁排序的场景，考虑：</p>
                            <ul class="list-disc pl-5 mt-2 text-gray-700 space-y-1">
                                <li>缓存Comparator实例</li>
                                <li>预计算比较键(使用Comparator.comparing)</li>
                                <li>对于大型列表，考虑并行流(parallelStream)</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center">
                <h3 class="text-xl font-bold mb-2">技术小馆</h3>
                <p class="mb-4 text-gray-400">探索编程之美，分享技术之道</p>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300 inline-flex items-center">
                    <i class="fas fa-external-link-alt mr-2"></i>
                    <span>访问语雀主页</span>
                </a>
            </div>
            <div class="mt-8 pt-8 border-t border-gray-800 text-center text-sm text-gray-500">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Add smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                document.querySelector(this.getAttribute('href')).scrollIntoView({
                    behavior: 'smooth'
                });
            });
        });

        // Add animation to method cards when they come into view
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    entry.target.classList.add('animate__animated', 'animate__fadeInUp');
                }
            });
        }, { threshold: 0.1 });

        document.querySelectorAll('.method-card').forEach(card => {
            observer.observe(card);
            card.classList.add('animate__animated');
        });
    </script>
</body>
</html>
```